/*
 * Copyright 2025 The JA-SIG Collaborative. All rights reserved. distributed with this file and
 * available online at
 */
package com.lap.auth.adapter.driving.query.project.repository;

import com.lap.auth.adapter.driving.query.project.ProjectQueryConverter;
import com.lap.auth.adapter.driving.query.project.mapper.ProjectQueryMapper;
import com.lap.auth.adapter.driving.query.project.po.ProjectQueryPo;
import com.lap.auth.application.project.dto.ProjectDto;
import com.lap.auth.application.project.dto.QueryProjectPageQuery;
import com.lap.auth.application.project.repository.ProjectQueryRepository;
import com.lap.framework.dto.page.PageResponse;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

@RequiredArgsConstructor
@Repository
public class ProjectQueryRepositoryImpl implements ProjectQueryRepository {

  private final ProjectQueryConverter converter;
  private final ProjectQueryMapper projectQueryMapper;

  @Override
  public PageResponse<ProjectDto> findByConditionPaged(QueryProjectPageQuery query) {
    long count = projectQueryMapper.countPageByCondition(query);
    if (count == 0L) {
      return PageResponse.ok(count);
    }
    List<ProjectQueryPo> list = projectQueryMapper.selectPageByCondition(query);
    return PageResponse.ok(converter.toDtoList(list), count);
  }
}
